
use std::fs::File;
use serde_json;
use log::{info, warn};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct MongodbConfig {
    pub db_url : String,
    pub db_name: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
    pub mongodb: MongodbConfig,
}

pub fn init_config(config_path: String) -> Config {
    warn!("Initializing config");
    let json_file = File::open(&config_path).unwrap();
    let config :Config = serde_json::from_reader(json_file).unwrap();
    config
}


#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn it_works() {
        let config = init_config(String::from("./config/config.json"));
        assert_eq!(config.mongodb.db_name, "bigfin" );
        assert_eq!(config.mongodb.db_url, "mongodb://192.168.1.179:27017");


    }
}